package com.wedo.mall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.e.library.activity.EActivity;
import com.e.library.adapter.Adapter;
import com.e.library.listener.EListener;
import com.wedo.mall.R;
import com.wedo.mall.activity.agent.AgentsActivity;
import com.wedo.mall.activity.agent.CategoriesActivity;
import com.wedo.mall.entity.AgentCategory;
import com.wedo.mall.util.WUrl;

import java.util.List;

/**
 * Created by lxy on 2017/6/10.
 */
public class AgentCategoryAdapterX extends Adapter<AgentCategory> {

    public AgentCategoryAdapterX(Context context, List<AgentCategory> datas) {
        super(context, datas);
    }

    @Override
    protected int layout() {
        return R.layout.item_goods_category;
    }

    @Override
    protected void bind(EHolder holder, AgentCategory category, int position) {
        ImageView iv_icon = holder.find(R.id.iv_icon);
        TextView tv_name = holder.find(R.id.tv_name);
        tv_name.setText(category.category_name);

        if (category.more == -1) {
            String icon = WUrl.url(category.app_icon);
            Glide.with(mContext).load(icon)
                    .error(R.drawable.home_dq)
                    .placeholder(R.drawable.home_dq)
                    .into(iv_icon);

        }else {
            Glide.with(mContext).fromResource()
                    .load(category.more)
                    .error(R.drawable.ic_home_more)
                    .placeholder(R.drawable.ic_home_more)
                    .into(iv_icon);
        }
    }

    public void listener(final EActivity activity){
        onItemClickListener = new EListener<AgentCategory>() {
            @Override
            public void onInvoked(View view, AgentCategory data, int position) {

                if (data.more == -1) {
                    AgentsActivity.toAgents(activity,data);

                } else {
                    //跳转到全部分类界面
                    activity.toActivity(CategoriesActivity.class);
                }

            }
        };
    }
}
